package com.web;

import com.pojo.SUser;
import com.service.IRegisterService;
import com.service.impl.RegisterServiceImpl;
import com.utils.JdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register.do")
public class RegisterServlet extends HttpServlet {
    private IRegisterService service =new RegisterServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*获取用户输入用户名*/
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("username");
        if(name==""){
            name=null;
        }
        SUser sUser = service.findInfo(name);
        /*判断用户名是否为空是否存在*/
        response.setContentType("text/html;charset=UTF-8");
        if(name==null){
            response.getWriter().write("{\"msg\":\"请输入用户名\",\"color\":\"red\"}");
        }
        if(sUser!=null){
            response.getWriter().write("{\"msg\":\"用户名已存在\",\"color\":\"red\"}");
        }
        if(name!=null&&sUser==null){
            response.getWriter().write("{\"msg\":\"用户名正确\",\"color\":\"green\"}");
        }
    }

}
